package com.moonshineproject.commands
{
	import com.moonshineproject.IDEModel;
	import com.moonshineproject.events.AddTabEvent;
	
	import flash.events.Event;

	public class AddTabCommand implements ICommand
	{
		private var model:IDEModel = IDEModel.getInstance();
		
		public function execute(event:Event):void
		{
			var e:AddTabEvent = AddTabEvent(event);
			// Remove empty 'New' editor or splashscreen
			if (model.activeEditor.isEmpty())
			{
				var index:int = model.editors.getItemIndex(model.activeEditor);
				
				if (index > -1) 
					model.editors.removeItemAt(index);
			}
			
			model.editors.addItem(e.tab);
		}
		
	}
}